package com.atguigu.rabbitmq.six;

import com.atguigu.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;

/**
 * ClassName: ReceiveLogsDirect01
 * Description:
 * Date: 2023/04/28 PM 2:13:51
 * <p>
 * project: atguigu-rabbitmq
 * package: com.atguigu.rabbitmq.six
 * email: 1085844536@qq.com
 * version:
 *
 * @author WangGuojian
 */
public class ReceiveLogsDirect01 {

    public static final String EXCHANGE_NAME = "direct_logs";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        // 声明一个交换机
        channel.exchangeDeclare(EXCHANGE_NAME, BuiltinExchangeType.DIRECT);
        // 声明一个队列
        channel.queueDeclare("console", false, false, false, null);

        channel.queueBind("console", EXCHANGE_NAME, "info");
        channel.queueBind("console", EXCHANGE_NAME, "warning");

        // 接收消息
        channel.basicConsume("console", true, (consumerTag, message) ->
                        System.out.println("ReceiveLogsDirect01控制台打印接收到的消息：" + new String(message.getBody())),
                consumerTag -> {
                }
        );
    }
}
